#创建一个浏览器对象
import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


class Driver:
    driver = ""
    def __init__(self):
        options = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
    def getScreeShot(self):
        #创建屏幕截图
        #图片路径：../images/2025-06-24-212524.png
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否存在，若不存在则创建文件夹
        #../images/20226-06-24
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        #2025-06-24-213621.png
        #图片路径：../images/2025-05-24/25-06-24-213423.png
        filename = sys._getframe().f_back.f_code.co_name+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") + ".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)


ForumDriver = Driver()